package com.yunbiao.ybbusstopplate.utils.core;

import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.yunbiao.ybbusstopplate.base.APP;
import com.yunbiao.ybbusstopplate.utils.net.ResourceUpdate;

import org.json.JSONArray;
import org.json.JSONObject;

public class SSTool {
    private static final String TAG = "SSTool";
    private static final ResourceUpdate resourceUpdate = new ResourceUpdate();
    public static void init(){}


    /**
     * @provide String res =  LayoutCache.getLayoutCacheAsString();
     * @param layoutCacheResult
     * @return
     */
    public static String getAdvertType(String layoutCacheResult){
        try {
            // 参考笔记 # android类型转换

            /**
             * center
             */
            JSONArray jsonArray = new JSONArray(layoutCacheResult);
            Object o = jsonArray.get(0);


            JSONObject jsonObject = new JSONObject(o.toString());
            Object center = jsonObject.get("center");

            /**
             * imageDetail
             */
            //get(0)
            JSONArray jsonArrayCenter = new JSONArray(center.toString());
            Object jsonArrayCenter0 = jsonArrayCenter.get(0);

            //jsonObject get("name")
            JSONObject jsonObjectImageDetail = new JSONObject(jsonArrayCenter0.toString());
            Object objImageDetail = jsonObjectImageDetail.get("imageDetail");

            /**
             * imagePlayType
             */
            JSONObject jsonObjectImagePlayType = new JSONObject(objImageDetail.toString());
            Object objImagePlayType = jsonObjectImagePlayType.get("imagePlayType");


            Log.d("advert", "判断中部广告/底部广告 center: " + objImagePlayType);

            return objImagePlayType.toString();


        } catch (Exception e) {
            Log.d("advert", "判断中部广告/底部广告 exception: " + e.getMessage());
        }

        return null;
    }


    public static void showTitleTip(String title) {
//        TextView textView = new TextView(HeartBeatClient.getInstance().getMainActivity());
        Log.d(TAG, "showTitleTip: title-->"+title);
        TextView textView = new TextView(APP.Companion.getAppContext());
        textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        textView.setBackgroundColor(Color.WHITE);
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(40);
        textView.setText(title);

//        Toast toast = new Toast(HeartBeatClient.getInstance().getMainActivity());
        Toast toast = new Toast(APP.Companion.getAppContext());
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setView(textView);
        toast.show();
    }
}
